package Lab06.Extra3;

import java.util.Random;

public class ShapeFactoriesTest {
    static Shape makeShape(IShapeFactory factory, double a, double b) {
        return factory.makeShape(a, b);
    }
    //每个getFactory()均被调用两次，通过比较两次的地址来判断是否为同一个实例

    public static void main(String[] args) {
        IShapeFactory[] factories = new IShapeFactory[6];
        factories[0] = RectangleFactory.getFactory();
        factories[1] = RhombusFactory.getFactory();
        factories[2] = EllipseFactory.getFactory();
        factories[3] = RectangleFactory.getFactory();
        factories[4] = RhombusFactory.getFactory();
        factories[5] = EllipseFactory.getFactory();
        Random rand = new Random();
        for (IShapeFactory factory : factories) {
            System.out.println(factory);
            Shape shape = makeShape(factory, rand.nextDouble(1,10), rand.nextDouble(1,10));
            System.out.println(shape.getClass().getSimpleName() + " : " + shape.calcArea()+"\n");
        }
    }
}
